﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data;
namespace LHWebApp.Json
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class JsonGetToiletInfoList : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string op = context.Request.Params["op"];
            switch (op)
            {
                case "GetMenuJobFeedback"://菜单 反馈记录
                    GetMenuJobFeedback(context);
                    break;
                case "GetMenuTemporaryMission"://菜单 临时任务
                    GetMenuTemporaryMission(context);
                    break;
                case "GetMenuSetCleanerList"://菜单 作业公厕设定-人员作业公厕设置
                    GetMenuSetCleanerList(context);
                    break;
                case "GetMenuSetToiletList"://菜单 作业公厕设定-公厕作业公厕查询
                    GetMenuSetToiletList(context);
                    break;
                case "GetMenuCleanerList"://菜单 人员管理列表
                    GetMenuCleanerList(context);
                    break;
                case "GetMenuCleanerTeam"://cmb 人员组织机构
                    GetMenuCleanerTeam(context);
                    break;
                case "GetToiletInfo"://实时在线统计 公厕实时监控统计
                    GetToiletInfo(context);
                    break;
                case "GetMenuAttendanceInfo"://菜单 考勤管理-考勤记录
                    GetMenuAttendanceInfo(context);
                    break;
                case "GetMenuToiletWorkInfo"://菜单 考勤管理-公厕作业
                    GetMenuToiletWorkInfo(context);
                    break;
                default:
                    context.Response.Write("{success: noFindOP}");
                    break;
            }
        }

        //菜单 考勤管理-考勤记录
        private void GetMenuAttendanceInfo(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string date = context.Request.Params["date"];
            string statue = context.Request.Params["statue"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuAttendanceInfo(clientNo, date, statue);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //姓名	清运队	班组	作业范围	上午签入	上午签出	下午签入	下午签出
                        jsonHelp.AddItem("name", dr["姓名"].ToString());
                        jsonHelp.AddItem("clientName", dr["清运队"].ToString());
                        jsonHelp.AddItem("clientName2", dr["班组"].ToString());
                        jsonHelp.AddItem("workAround", dr["作业范围"].ToString());
                        jsonHelp.AddItem("amIN", dr["上午签入"].ToString());
                        jsonHelp.AddItem("amOUT", dr["上午签出"].ToString());
                        jsonHelp.AddItem("pmIN", dr["下午签入"].ToString());
                        jsonHelp.AddItem("pmOUT", dr["下午签出"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 考勤管理-公厕作业
        private void GetMenuToiletWorkInfo(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string date = context.Request.Params["date"];
            string name = context.Request.Params["name"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuToiletWorkInfo(clientNo, date, name);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        jsonHelp.AddItem("name", dr[0].ToString());
                        jsonHelp.AddItem("time", dr["ORIENTATION_TIME"].ToString());
                        jsonHelp.AddItem("toiletName", dr[2].ToString());
                        jsonHelp.AddItem("sex", dr["SEX"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }
        
        //菜单 反馈记录
        private void GetMenuJobFeedback(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuJobFeedback(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        jsonHelp.AddItem("clientNo", dr["CLIENT_NO"].ToString());
                        jsonHelp.AddItem("time", dr["ORIENTATION_TIME"].ToString());
                        jsonHelp.AddItem("roadName", dr["ROADNAME"].ToString());
                        jsonHelp.AddItem("location", dr["LOCATION"].ToString());
                        //jsonHelp.AddItem("detail", dr["DETAIL"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 临时任务
        private void GetMenuTemporaryMission(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuTemporaryMission(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //下发时间	任务时间	任务道路	任务地点	任务要求	负责班组	任务状态
                        jsonHelp.AddItem("missionDate", dr["任务时间"].ToString());
                        jsonHelp.AddItem("missionToilet", dr["任务地点"].ToString());
                        jsonHelp.AddItem("missionAD", dr["任务道路"].ToString());
                        jsonHelp.AddItem("clientName", dr["负责班组"].ToString());
                        jsonHelp.AddItem("missionStatus", dr["任务状态"].ToString());
                        jsonHelp.AddItem("missionAsk", dr["任务要求"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 作业公厕设定-人员作业人员设置
        private void GetMenuSetCleanerList(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuSetCleanerList(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //序号	姓名	所属分组	维保公厕	维保开始时间	维保结束时间	设置时间
                        jsonHelp.AddItem("vid", dr["序号"].ToString());
                        jsonHelp.AddItem("name", dr["姓名"].ToString());
                        jsonHelp.AddItem("clientName", dr["所属分组"].ToString());
                        jsonHelp.AddItem("ToiletName", dr["维保公厕"].ToString());
                        jsonHelp.AddItem("startDate", dr["维保开始时间"].ToString());
                        jsonHelp.AddItem("endDate", dr["维保结束时间"].ToString());
                        jsonHelp.AddItem("settingDate", dr["设置时间"].ToString());

                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 作业公厕设定-公厕作业公厕查询
        private void GetMenuSetToiletList(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuSetToiletList(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //序号	公厕名称	所属分组	负责维保人员（按维保时间先后顺序排列）

                        jsonHelp.AddItem("vid", dr["序号"].ToString());
                        jsonHelp.AddItem("ToiletName", dr["公厕名称"].ToString());
                        jsonHelp.AddItem("clientName", dr["所属分组"].ToString());
                        jsonHelp.AddItem("peopleNames", dr["负责维保人员（按维保时间先后顺序排列）"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //菜单 人员管理列表
        private void GetMenuCleanerList(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string name = context.Request.Params["name"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuCleanerList(clientNo, name);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {

                        jsonHelp.AddItem("vid", dr["VID"].ToString());
                        jsonHelp.AddItem("name", dr["NAME"].ToString());
                        jsonHelp.AddItem("simNO", dr["SIMCARD_NO"].ToString());
                        jsonHelp.AddItem("clientNO", dr["CLIENT_NO"].ToString());
                        jsonHelp.AddItem("sex", dr["SEX"].ToString());
                        jsonHelp.AddItem("phone", dr["PHONE"].ToString());
                        jsonHelp.AddItem("worktype", dr["WORKTYPE"].ToString());
                        jsonHelp.AddItem("birthDay", dr["BIRTHDAY"].ToString());
                        jsonHelp.AddItem("workDay", dr["WORKDATE"].ToString());

                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //cmb 人员组织机构
        private void GetMenuCleanerTeam(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetMenuCleanerTeam(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {

                        jsonHelp.AddItem("CLIENT_NO", dr["CLIENT_NO"].ToString());
                        jsonHelp.AddItem("CLIENT_NAME", dr["CLIENT_NAME"].ToString());
                        //jsonHelp.AddItem("PARENT_NO", dr["PARENT_NO"].ToString());
                        //jsonHelp.AddItem("CREATE_DATE", dr["CREATE_DATE"].ToString());
                        //jsonHelp.AddItem("COLOUR", dr["COLOUR"].ToString());
                        //jsonHelp.AddItem("DATEDIFF", dr["DATEDIFF"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //实时在线统计 公厕实时监控统计
        private void GetToiletInfo(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];

            try
            {
                DataSet ds = LHWebApp.ServicesToilet.GetToiletInfo(clientNo);
                DataTable dt = ds.Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr[0].ToString() == "公厕名称")
                        {
                            continue;
                        }
                        jsonHelp.AddItem("LicensePlate", dr[0].ToString());
                        jsonHelp.AddItem("Location", dr[1].ToString());
                        jsonHelp.AddItem("section3", dr[2].ToString());
                        jsonHelp.AddItem("CarType", dr[3].ToString());
                        jsonHelp.AddItem("section5", dr[4].ToString());
                        jsonHelp.AddItem("section6", dr[5].ToString());
                        jsonHelp.AddItem("section7", dr[6].ToString());
                        jsonHelp.AddItem("section8", dr[7].ToString());
                        jsonHelp.AddItem("section9", dr[8].ToString());
                        jsonHelp.AddItem("section10", dr[9].ToString());
                        jsonHelp.AddItem("Lng", dr[10].ToString());
                        jsonHelp.AddItem("Lat", dr[11].ToString());
                        jsonHelp.AddItem("section13", dr[12].ToString());
                        jsonHelp.AddItem("section14", dr[13].ToString());
                        jsonHelp.AddItem("section15", dr[14].ToString());

                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

